package com.mail.server.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mail.dubbo.api.SmsHomeRecommendSubjectApi;
import com.mail.model.db.SmsHomeRecommendSubject;
import com.mail.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsHomeRecommendSubjectService {

    @DubboReference
    private SmsHomeRecommendSubjectApi smsHomeRecommendSubjectApi;

    public void addSubject(List<SmsHomeRecommendSubject> smsHomeRecommendSubjectList) {
        for (SmsHomeRecommendSubject smsHomeRecommendSubject : smsHomeRecommendSubjectList) {
            smsHomeRecommendSubjectApi.save(smsHomeRecommendSubject);
        }
    }

    public void deleteSubject(List<Long> ids) {
        smsHomeRecommendSubjectApi.deleteSubject(ids);
    }

    public PageResult getSubjectByPage(Long pageNum, Long pageSize, String subjectName, Integer recommendStatus) {
        Page<SmsHomeRecommendSubject> page = smsHomeRecommendSubjectApi.getSubjectByPage(pageNum, pageSize, subjectName, recommendStatus);
        return new PageResult(Long.parseLong(String.valueOf(page.getCurrent())), Long.parseLong(String.valueOf(page.getSize())), Long.parseLong(String.valueOf(page.getTotal())), page.getRecords());
    }

    public void updateSubject(List<Long> ids, Integer recommendStatus) {
        for (Long id : ids) {
            smsHomeRecommendSubjectApi.updateSubject(id, recommendStatus);
        }
    }

    public void updateSortSubject(Long id, Integer sort) {
        smsHomeRecommendSubjectApi.updateSortSubject(id, sort);
    }
}
